# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: app-text/kindlegen/kindlegen-2.9-r1.ebuild,v 1.3 2014/06/17 11:30:00 itspec.ru Exp $

EAPI=5

inherit eutils

KG_PV="${PV/./_}"
KG_BUILD="0730-890adc2"

DESCRIPTION="Amazon's converter their HTML, XHTML, XML (OPF/IDPF format), or ePub source into a Kindle Book"
HOMEPAGE="http://www.amazon.com/gp/feature.html?docId=1000765211"
SRC_URI="http://kindlegen.s3.amazonaws.com/kindlegen_linux_2.6_i386_v${KG_PV}.tar.gz -> kindlegen_linux_2.6_i386_v${KG_PV}-${KG_BUILD}.tar.gz"

SLOT="0"
LICENSE="KindleGen-EULA"
RESTRICT="mirror"

KEYWORDS="~x86 ~amd64"
IUSE=""

RDEPEND=""
DEPEND=""

S=${WORKDIR}

RESTRICT="strip mirror"

rdos2unix() {
    find . -name '*'.$1 -type f -print0 | while read -d $'\0' file
    do
        edos2unix "$file" || die "Failed to convert line-endings of all .$1 files";
    done
}

src_prepare() {
    rdos2unix txt
    rdos2unix html
}

src_install() {
    exeinto /opt/bin
    doexe kindlegen || die
    dodoc EULA.txt "KindleGen Legal Notices 2013-02-19 Linux.txt" docs/english/*.*
}
